package cn.webrx;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) {
        //d:/abc/g1.jpg 复制到项目目录下。
        String p = "d:/abc/g1.jpg";
        try (
                var fis = new FileInputStream(p);
                var fos = new FileOutputStream("girl3.jpg")
        ) {

            //fos.write(fis.readAllBytes());

            //int b = 0;
            //while((b = fis.read())!=-1){
            //    fos.write(b);
            //}

            //推荐使用如下复制文件
            //byte[] buf = new byte[10240];
            //int len = 0;
            //while ((len = fis.read(buf)) != -1) {
            //    fos.write(buf, 0, len);
            //}


            fis.transferTo(fos);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
